package com.cn.kabalifeuser.ui.service.adapter;

import android.widget.TextView;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.cn.kabalifeuser.R;
import com.cn.kabalifeuser.ui.service.bean.StrListBean;

import java.util.List;

/**
 * Created by 晓林 on 2020/10/16.
 * function:
 */
public class StrListAdapter2 extends BaseQuickAdapter<StrListBean.SubsetBean, BaseViewHolder> {
    private int selectedPos = -1;
    private int oldPos = -1;

    public StrListAdapter2(int layoutResId, @Nullable List<StrListBean.SubsetBean> data) {
        super(layoutResId, data);

    }

    @Override
    protected void convert(BaseViewHolder helper, final StrListBean.SubsetBean item) {
        TextView tvTitle = helper.getView(R.id.tv_content);

        tvTitle.setText(item.getName());
        if (item.isCheck()) {
            //相同设置高亮
            tvTitle.setTextColor(this.mContext.getResources().getColor(R.color.font_000));
        } else {
            //不同设置
            tvTitle.setTextColor(this.mContext.getResources().getColor(R.color.text_909090));
        }
    }

    public void refreshItem(int position) {
        if (selectedPos != -1) {
            oldPos = selectedPos;
        }
        selectedPos = position;
        if (oldPos != -1) {
            notifyItemChanged(oldPos);
        }
        notifyItemChanged(selectedPos);
    }
}
